import Taro from '@tarojs/taro';
import { View } from '@tarojs/components';
import './index.scss';
import utils from '@/utils/util'
import DrugItem from '@/components/drugItem/index';

class DrugDetails extends Taro.Component {
    constructor(props) {
        super(props);
        this.state = { 
            drugDetails:{}
         }
    }
    componentWillMount(){
        let drugDetails = this.$router.params;
        this.setState({
            drugDetails
        })
    }
    config = {
        navigationBarTitleText: '药品详情'
    }
    render() { 
        const { drugDetails} = this.state;
        return ( 
            <View className='pl-2-5 pr-2-5 mt-2-5 ov_h'>
                <DrugItem isDetails isuse drugItem={drugDetails}
                  renderSolt={
                    <View className='flex flex-item-l-end'>
                          <View className={`default-btn samll mt-4-5 mr-0 ${(drugDetails.status == 3 || drugDetails.status == 4) ? 'off':''}`} 
                            onClick={()=>{
                              if ((drugDetails.status == 3 || drugDetails.status == 4 )){
                                  return utils.showtoast(drugDetails.msg); 
                                }else {
                                  if (Number(drugDetails.usernum) >= Number(drugDetails.quantity)) {
                                    return utils.showtoast('该药品已用完') 
                                }
                                //   if (drugDetails.isJxq === '已过期') {
                                //       return utils.showtoast('该药品已处于过期状态，无法操作')
                                //   }
                                }
                                Object.keys(drugDetails).map((items) => {
                                    drugDetails[items] = encodeURIComponent(drugDetails[items])
                                })
                                Taro.navigateTo({
                                    url: '/pages/useDrug/index?' + utils.queryconcat(drugDetails)
                                })
                          }}
                          >{(   drugDetails.isJxq === '已过期') && drugDetails.status!=3   ? '回收药品':'使用药品'}</View>
                    </View>
                }
                ></DrugItem>
            </View>
         );
    }
}
 
export default DrugDetails;